google.load('visualization', '1', {packages:['table']});


// final function that builds the market table from the json object
function drawRankingTable(rankingTableResp0) 
{

    var rankingTableResp = eval('(' + rankingTableResp0.responseText + ')'); 
	var data = new google.visualization.DataTable();
	var nbAssets = rankingTableResp.assetsList.length
	var nbPlayers = rankingTableResp.assetsList[0].rankedPlayers.length
	
	data.addColumn('number', "rang");
	for (var a = 0; a < nbAssets; a++)
	{
		data.addColumn('string', rankingTableResp.assetsList[a].name);
	}
	
	data.addRows(nbPlayers);
	for (var p = 0; p < nbPlayers; p++)
	{
	    data.setCell(p, 0, p + 1 );
	    
	    for (var a = 0; a < nbAssets; a++)
	    {
		    data.setCell(p, a+1, rankingTableResp.assetsList[a].rankedPlayers[p].name );
		};
	}
	var table = new google.visualization.Table(document.getElementById('rankingtable_div'));	
	table.draw(data, {width: 330, height: 300, title: 'Rang selon qui chope'});
}

var updateRankingTable = function() 
{
    var args = { type:"get", url:"/json/getRanking/", complete:drawRankingTable };
    $.ajax(args);
    return false;
};

$(document).ready( function() 
{
    updateRankingTable();
});
    
